export function getWeekTime() {
    var currentFirstDate;
    var formatDate = function (date) {

        var day = date.getDate();
        var week = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()];
        var obj = {
            day: day,
            week: week
        }
        return obj;
    };

    var addDate = function (date, n) {
        date.setDate(date.getDate() + n);
        return date;
    };

    var setDate = function (date) {
        var week = date.getDay() - 1;
        date = addDate(date, week * -1);
        currentFirstDate = new Date(date);

        var arr = [];
        for (var i = 0; i < 7; i++) {
            var a = formatDate(i == 0 ? date : addDate(date, 1));   //星期一开始
            arr.push(a)
        }
        return arr;
    };
    setDate(new Date())
    var num = 0;//num为0时表示当前周，递增或递减时周数也递增或递减
    return setDate(addDate(currentFirstDate, 7 * num));
}

export function splitFirstLetter(data) {
    let map = {};
    let newArr = [];
    for (let i = 0; i < 26; i++) {
        const key = String.fromCharCode(65 + i) //A-Z赋给key当作键
        map[key] = {
            title: key,
            items: []
        }

        data.forEach(v=> {
            //遍历数组
            var name = v.userName
            let firstIndex = name.charAt(0).toUpperCase();//首字母
            if (firstIndex.toUpperCase() == String.fromCharCode(65 + i)) {//统一转成大写进行逐个判断
                map[key].items.push(v)//push进相对应的数组里头
            }
        })
        // //如果当前的数组里头为空，则跳过。
        if (map[key].items === undefined || map[key].items.length == 0) {
            continue;
        } else {
            newArr.push(map[key])//将分类好的每个对象 合并在一个数组里面
        }
    }
    return newArr
}